if (typeof(TRAVIAN_CONFIG) != 'boolean') {
	var TRAVIAN_CONFIG = true;

	var TrvnCfg = {};
	var TrvnCfgManager = {
		configInitialized : false,
		configFilePath : null,
		saveConfigTimer : 0,
		reload : function(path) {
			if (!path || path == "" || !FileIO.open(path).exists()) {
				var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
				fp.init(window, "选择配置文件位置", fp.modeOpen);
				fp.appendFilters(fp.filterXML);
				if (fp.show() == fp.returnOK) {
					path = fp.file.path;
				} else {
					return null;
				}
			}
			this.configFilePath = path;
			TrvnCfg = XMLUtils.readFromFile(path);
			$extend(TrvnCfg, {
				getCurrentAccount : function() {
					return this.accounts[this.currentAccountId];
				},
				getCurrentServer : function() {
					return this.servers[this.getCurrentAccount().serverId];
				},
				getCurrentVillage : function() {
					var curAccount = this.getCurrentAccount();
					if (!curAccount || !curAccount.currentVillageId) {
						return null;
					}
					return curAccount.villages[curAccount.currentVillageId];
				},
				queryUrl : function(page) {
					return this.servers[this.getCurrentAccount().serverId].base + "/" + page;
				},
				queryXPath : function(xpath) {
					return TrvnData.xPath[xpath];
				}
			});
			this.configInitialized = true;
			return path;
		},
		init : function(path) {
			if (!this.configInitialized) {
				return this.reload(path);
			}
			return this.configFilePath;
		},
		save : function() {
			XMLUtils.writeIntoFile(TrvnCfg, this.configFilePath);
			this.saveConfigTimer = 0;
		},
		scheduleSaveConfig : function() {
			if (this.saveConfigTimer > 0) {
				return;
			}
			this.saveConfigTimer = setTimeout(function() {
				TrvnCfgManager.save();
			}, 2 * 60 * 1000);
		},
		stopSaveConfigTimer : function() {
			if (this.saveConfigTimer > 0) {
				clearTimeout(this.saveConfigTimer);
			}
		}
	};
}